package com.ewzj.bigdata.mvp.ui.activity

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.View
import com.ewzj.bigdata.R
import com.ewzj.bigdata.app.config.AppKey
import com.ewzj.bigdata.app.extensions.initwebview
import com.ewzj.bigdata.app.utils.Apputils
import com.ewzj.bigdata.di.component.DaggerWebviewActivityComponent
import com.ewzj.bigdata.di.module.WebviewActivityModule
import com.ewzj.bigdata.mvp.contract.WebviewActivityContract
import com.ewzj.bigdata.mvp.presenter.WebviewActivityPresenter
import com.jakewharton.rxbinding2.view.RxView
import com.jess.arms.base.BaseActivity
import com.jess.arms.di.component.AppComponent
import kotlinx.android.synthetic.main.activity_web_view.*
import kotlinx.android.synthetic.main.path_loading.*
import kotlinx.android.synthetic.main.titile_red.*


class WebViewActivity : BaseActivity<WebviewActivityPresenter>(),WebviewActivityContract.View{
    val tiitle by lazy{intent.getStringExtra(AppKey.EXTRA_String)}
    val url by lazy{intent.getStringExtra(AppKey.EXTRA_url)}
    override fun initData(savedInstanceState: Bundle?) {
        RxView.clicks(iv_back).subscribe({finish()})
        webwebview.initwebview(rl_pathloading)
        if (tiitle.isNullOrEmpty()){
            ll_title.visibility= View.GONE
        }else{
            tv_title.text=tiitle
        }
        if (url.isNullOrBlank()){
            finish()
        }
        webwebview.loadUrl(url)
        Apputils.Utils.setPathandStart(rl_pathloading)
    }

    override fun setupActivityComponent(appComponent: AppComponent?) {
        DaggerWebviewActivityComponent.builder().appComponent(appComponent)
                .webviewActivityModule(WebviewActivityModule(this))
                .build().inject(this)
    }

    override fun initView(savedInstanceState: Bundle?): Int {
       return R.layout.activity_web_view
    }

    override fun showLoading() {
    }

    override fun launchActivity(intent: Intent?) {
    }

    override fun hideLoading() {
    }

    override fun killMyself() {
    }

    override fun showMessage(message: String?) {
    }

    companion object{
        fun startWebView(context: Context,title: String,url: String){
            var intent=Intent(context,WebViewActivity::class.java)
            intent.putExtra(AppKey.EXTRA_String,title)
            intent.putExtra(AppKey.EXTRA_url,url)
            context.startActivity(intent)
        }
    }

    override fun useFragment(): Boolean {
        return false
    }
}
